package com.scuec.tourismwebsite.service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.scuec.tourismwebsite.entity.Admin;
import com.scuec.tourismwebsite.mapper.AdminMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.List;

@Service
public class AdminServiceImpl implements AdminService {
    @Autowired
    private AdminMapper adminMapper;

    @Override
    public List<Admin> findAdminAll() {
        return adminMapper.findAdminAll();
    }

    @Override
    public List<Admin> findAdminByEm(String email) {
        return adminMapper.findAdminByEm(email);
    }

    @Override
    public int deleteAdminById(int admin_id) {
        return adminMapper.deleteAdminById(admin_id);
    }

    @Override
    public Integer addAdmin(Admin admin) {
        return adminMapper.addAdmin(admin);
    }

    @Override
    public Admin findAdminByEmail(String email) {
        return adminMapper.findAdminByEmail(email);
    }

    @Override
    public PageInfo<Admin> findAdminPages(Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        List<Admin> lists = adminMapper.findAdminAll();
        PageInfo<Admin> pageInfo = new PageInfo<>(lists);
        return pageInfo;
    }

    @Override
    public PageInfo<Admin> findAdminPage(String nickname, Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        List<Admin> lists = adminMapper.findAdminByName(nickname);
        PageInfo<Admin> pageInfo = new PageInfo<>(lists);
        return pageInfo;
    }
}

